<template>
<a-modal :maskClosable="false"
        :title="title"
        :width="800"
        :visible="visible"
        :confirmLoading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
        cancelText="关闭">

<a-spin :spinning="confirmLoading">
   <a-form-model ref="form"  v-bind="layout"  :model="model" :rules="validatorRules">

      <a-form-model-item label="${column.columnComment}"  prop="id">
           <a-input placeholder="请输入$comment"  v-model="model.id"  />
        </a-form-model-item >
      <a-form-model-item label="创建人" required prop="createBy">
           <a-input placeholder="请输入创建人"  v-model="model.createBy"  />
        </a-form-model-item >
      <a-form-model-item label="创建时间" required prop="createTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.createTime"  />
        </a-form-model-item >
      <a-form-model-item label="修改人"  prop="updateBy">
           <a-input placeholder="请输入修改人"  v-model="model.updateBy"  />
        </a-form-model-item >
      <a-form-model-item label="修改时间"  prop="updateTime">
        <a-date-picker showTime format='YYYY-MM-DD HH:mm:ss'  v-model="model.updateTime"  />
        </a-form-model-item >
      <a-form-model-item label="所属组织" required prop="sysOrgCode">
           <a-input placeholder="请输入所属组织"  v-model="model.sysOrgCode"  />
        </a-form-model-item >
      <a-form-model-item label="状态0无效 1有效" required prop="status">
           <a-input placeholder="请输入状态0无效 1有效"  v-model="model.status"  />
        </a-form-model-item >
      <a-form-model-item label="删除标识" required prop="delFlag">
           <a-input placeholder="请输入删除标识"  v-model="model.delFlag"  />
        </a-form-model-item >
      <a-form-model-item label="备注"  prop="remark">
           <a-input placeholder="请输入备注"  v-model="model.remark"  />
        </a-form-model-item >
      <a-form-model-item label="销售类型 0线下 1线上" required prop="saleType">
           <a-input placeholder="请输入销售类型 0线下 1线上"  v-model="model.saleType"  />
        </a-form-model-item >
      <a-form-model-item label="商品数量" required prop="cpQuantity">
           <a-input placeholder="请输入商品数量"  v-model="model.cpQuantity"  />
        </a-form-model-item >
      <a-form-model-item label="商品id" required prop="cpId">
           <a-input placeholder="请输入商品id"  v-model="model.cpId"  />
        </a-form-model-item >
      <a-form-model-item label="门店id" required prop="storeId">
           <a-input placeholder="请输入门店id"  v-model="model.storeId"  />
        </a-form-model-item >
      </a-form-model>
    </a-spin>
</a-modal>
</template>

<script>
  import { httpAction,putAction,getAction,postAction} from '@/api/manage'

  export default {
    name: "ordStoreCpRuleModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        layout: {
           labelCol: { span: 4 },
           wrapperCol: { span: 14 },
        },
        confirmLoading: false,
        validatorRules:{
        createBy:[{ required: true, message: '请输入创建人!' }],
        createTime:[{ required: true, message: '请输入创建时间!' }],
        sysOrgCode:[{ required: true, message: '请输入所属组织!' }],
        status:[{ required: true, message: '请输入状态0无效 1有效!' }],
        delFlag:[{ required: true, message: '请输入删除标识!' }],
        saleType:[{ required: true, message: '请输入销售类型 0线下 1线上!' }],
        cpQuantity:[{ required: true, message: '请输入商品数量!' }],
        cpId:[{ required: true, message: '请输入商品id!' }],
        storeId:[{ required: true, message: '请输入门店id!' }],
        },
        url: {
          add: "/system/ordStoreCpRule",
          edit: "/system/ordStoreCpRule",
        },
      }
    },
    created () {
        this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
          this.model = Object.assign({}, record);
          this.visible = true;
      },
      close () {
          this.$refs.form.clearValidate();
          this.$emit('close');
          this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
              method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                 that.$message.success(res.message);
                 that.$emit('ok');
              }else{
                 that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
            return false;
         }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>
